package com.ruoyi.web.controller.module.union;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.market.domain.Banner;
import com.ruoyi.market.service.IBannerService;
import com.ruoyi.order.domain.OrderGift;
import com.ruoyi.order.domain.OrderPk;
import com.ruoyi.order.service.IOrderGiftService;
import com.ruoyi.order.service.IOrderPkService;
import com.ruoyi.system.service.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 服务项目信息
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/union/index")
public class UnionIndexController extends BaseController
{
    @Autowired
    private IBannerService bannerService;

    @Autowired
    private IOrderPkService orderPkService;

    @Autowired
    private IOrderGiftService orderGiftService;

    @Autowired
    private ISysDictDataService dictDataService;

    @PostMapping("/getIndexList")
    public AjaxResult getIndexList(HttpServletRequest request, @RequestBody Map<String, Object> params)
    {
        AjaxResult ajax = AjaxResult.success();
        String shopId = request.getHeader("ShopId"); // 店铺id
        if (shopId == null || shopId.equals("")) {
            return error("店铺基本配置失败，参数错误");
        }
        
        PageHelper.startPage(1, 5).setReasonable(true);
        PageHelper.orderBy("banner_sort asc");
        Banner banner = new Banner();
        banner.setShopId(shopId);
        // 帐号状态（0正常 1停用）
        banner.setStatus(UserConstants.NORMAL);
        banner.setBannerImage(UserConstants.IMAGE_TYPE_BANNER);
        List<Banner> bannerList = bannerService.selectBannerList(banner);
        ajax.put("bannerList", bannerList);

        PageHelper.clearPage();
        PageHelper.startPage(1, 3).setReasonable(true);
        PageHelper.orderBy("total_user_amount desc");
        OrderPk orderPk = new OrderPk();
        orderPk.setShopId(shopId);
        orderPk.setPkStatus(UserConstants.STATUS_GOING);
        List<OrderPk> orderPkList = orderPkService.selectOrderPkList(orderPk);
        ajax.put("orderPkList", orderPkList);

        PageHelper.clearPage();
        PageHelper.startPage(1, 5).setReasonable(true);
        PageHelper.orderBy("create_time desc");
        OrderGift orderGift = new OrderGift();
        orderGift.setShopId(shopId);
        orderGift.setPayStatus(UserConstants.PAY_STATUS_PAID);
        List<OrderGift> orderGiftList = orderGiftService.selectOrderGiftList(orderGift);
        ajax.put("orderGiftList", orderGiftList);

        PageHelper.clearPage();
        SysDictData dictData = new SysDictData();
        dictData.setDictType("app_service_constellation");
        List<SysDictData> constellationList = dictDataService.selectDictDataList(dictData);
        ajax.put("constellationList", constellationList);
        return ajax;
    }

}
